﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace XMLSQL.Admin
{
    public partial class ManageUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ErrorLabel.Visible = false;
            }
        }
        protected void Submitbt_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string susername = tbusername.Text;
                string semail = tbemail.Text;
                string spassword = tbpassword.Text;
                string spassword2 = tbpassword2.Text;
                string srole = tbrole.SelectedValue;

                try
                {
                    Membership.CreateUser(susername, spassword, semail);
                    Roles.AddUserToRole(susername, srole);

                    Response.Redirect("~/Admin/CRUDUser.aspx");
                }
                catch (Exception ex)
                {
                    //silent
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text = "Error creating user: " + ex.Message;
                }
            }
        }
    }
}